package com.thread;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;
import java.util.stream.IntStream;

/**
 * @author: mayu
 * @date: 2021年04月09日 16:43
 * 两个线程交替打印
 */
public class TestABC123WithLockSupport {
    static Thread t1 = null, t2 = null;

    public static void main(String[] args) {

        t1 = new Thread(() -> {
            Arrays.asList("A", "B", "C", "D", "E", "F").stream().forEach(item -> {
                System.out.print(item);
                LockSupport.unpark(t2);
                LockSupport.park();
            });
        });

        t2 = new Thread(() -> {
            IntStream.range(1, 7).forEach(item -> {
                LockSupport.park();
                System.out.print(item);
                LockSupport.unpark(t1);
            });
        });

        t1.start();
        t2.start();
    }
}
